import unittest
from login import Login
from mytest import MyTestCase
from config import get_cfg


class LoginTestCase(MyTestCase):
    """登录测试"""

    def setUp(self) -> None:
        super().setUp()
        self.username = Login.username

    def tearDown(self) -> None:
        self.driver.quit()

    def test_01_login(self):
        """用户名为空，密码不为空"""
        msg = Login(self.driver).user_login('', password='123456')
        self.assertEqual('请输入用户名！', msg)

    def test_02_login(self):
        """用户名不为空，密码为空"""
        msg = Login(self.driver).user_login(password='')
        self.assertEqual('请输入密码！', msg)

    def test_03_login(self):
        """用户名密码都为空"""
        msg = Login(self.driver).user_login('', '')
        self.assertEqual('请输入用户名！', msg)

    def test_04_login(self):
        """用户名正确，密码错误"""
        msg = Login(self.driver).user_login(password='111111')
        self.assertEqual('用户密码错误，登录失败！', msg)

    def test_05_login(self):
        """用户名错误"""
        msg = Login(self.driver).user_login(username='11111')
        self.assertEqual('用户名不存在', msg)

    def test_06_login(self):
        """用户名密码正确"""
        msg = Login(self.driver).user_login()
        self.assertEqual(self.username, msg)


if __name__ == '__main__':
    unittest.main()
